]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
loginManager: Get user proxy for UID
authorFlorian Müllner <fmuellner@gnome.org>
Thu, 13 Feb 2025 01:51:14 +0000 (02:51 +0100)
committerMarge Bot <marge-bot@gnome.org>
Thu, 13 Feb 2025 11:31:34 +0000 (11:31 +0000)
Using the user object at `/org/freedesktop/login1/User/self` is
convenient, but has the caveat that login1 does not emit the
`PropertiesChanged` signal for the object.

That is indeed logical, as for signal emissions there is no
sender that can be used to resolve `self`.

The new TimeLimitsManager depends on change notifications for
user properties, so stop using the `self` shorthand and instead
create the User proxy for the user's UID.

Related: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/8185
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3636>

data/dbus-interfaces/org.freedesktop.login1.Manager.xml
js/misc/loginManager.js

index f40d498dcc1cde94e0d11afbda97d3eb3e31afae..7e0fc225e10b95fa106e5226539a5611492a1dc6 100644 (file)
       <arg type="s" direction="in"/>
       <arg type="o" direction="out"/>
     </method>
+    <method name="GetUser">
+      <arg type="u" direction="in"/>
+      <arg type="o" direction="out"/>
+    </method>
     <method name="ListSessions">
       <arg name="sessions" type="a(susso)" direction="out"/>
     </method>
index 4bbe7c42cd7ee9d7a02f61fda301bfd7a8164c8b..d928ff0220bb25fd48a9ad7f3b0c12cdff7a0703 100644 (file)
@@ -1,6 +1,7 @@
 import GLib from 'gi://GLib';
 import Gio from 'gi://Gio';
 import GioUnix from 'gi://GioUnix';
+import Shell from 'gi://Shell';
 import * as Signals from './signals.js';
 
 import {loadInterfaceXML} from './fileUtils.js';
@@ -95,17 +96,26 @@ class LoginManagerSystemd extends Signals.EventEmitter {
         this._proxy = new SystemdLoginManager(Gio.DBus.system,
             'org.freedesktop.login1',
             '/org/freedesktop/login1');
-        this._userProxy = new SystemdLoginUser(Gio.DBus.system,
-            'org.freedesktop.login1',
-            '/org/freedesktop/login1/user/self');
         this._proxy.connectSignal('PrepareForSleep',
             this._prepareForSleep.bind(this));
         this._proxy.connectSignal('SessionRemoved',
             this._sessionRemoved.bind(this));
     }
 
-    getCurrentUserProxy() {
-        return this._userProxy;
+    async getCurrentUserProxy() {
+        if (this._userProxy)
+            return this._userProxy;
+
+        const uid = Shell.util_get_uid();
+        try {
+            const [objectPath] = await this._proxy.GetUserAsync(uid);
+            this._userProxy = await SystemdLoginUser.newAsync(
+                Gio.DBus.system, 'org.freedesktop.login1', objectPath);
+            return this._userProxy;
+        } catch (error) {
+            logError(error, `Could not get a proxy for user ${uid}`);
+            return null;
+        }
     }
 
     async getCurrentSessionProxy() {
@@ -115,14 +125,15 @@ class LoginManagerSystemd extends Signals.EventEmitter {
         let sessionId = GLib.getenv('XDG_SESSION_ID');
         if (!sessionId) {
             log('Unset XDG_SESSION_ID, getCurrentSessionProxy() called outside a user session. Asking logind directly.');
-            let [session, objectPath] = this._userProxy.Display;
+            const userProxy = await this.getCurrentUserProxy();
+            let [session, objectPath] = userProxy.Display;
             if (session) {
                 log(`Will monitor session ${session}`);
                 sessionId = session;
             } else {
                 log('Failed to find "Display" session; are we the greeter?');
 
-                for ([session, objectPath] of this._userProxy.Sessions) {
+                for ([session, objectPath] of userProxy.Sessions) {
                     let sessionProxy = new SystemdLoginSession(Gio.DBus.system,
                         'org.freedesktop.login1',
                         objectPath);